<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>欢迎使用CRM管理系统</title>
    <link rel="stylesheet" href="${basePath }/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="${basePath }/css/style.css" type="text/css" />
    <script type="text/javascript" src="${basePath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath }/js/bootstrap.min.js"></script>
    <style type="text/css">
    	select {
			width:100px;    	
    	}
    </style>
</head>
<body>
	<div class="navbar">
        <div class="navbar-inner">
            <div class="navbar-inner">
	            <div class="container">
	                <a href="${basePath }/message" class="brand">凯盛CRM管理系统</a>
	                <div class="nav-collapse">
	                    <ul class="nav">
	                        <li><a href="${basePath }/message">最新动态</a></li>
	                        <li  class="active"><a href="${basePath }/contacts/list">联系人</a></li>
	                        <li><a href="${basePath }/task/list">日程安排</a></li>
	                        <li><a href="${basePath }/deal/list">业务机会</a></li>
	                    </ul>
	                    <ul class="nav pull-right">
	                        <li><a href="#">${user.username }</a></li>
	                        <li class="divider-vertical"></li>
	                        <li><a href="${basePath }/user/info">账号设置</a></li>
	                        <li><a href="${basePath }/user/loginout">退出</a></li>
	                    </ul>
	                </div>
	            </div>
	        </div>
        </div>
    </div>
    <div id="content" class="container">
        <div class="span9">
            <ul class="breadcrumb" style="vertical-align:top">
                <li class="active">编辑联系人</li>
            </ul>
            <div class="well">
                <form class="form-horizontal" action="${basePath }/contacts/save" method="post" id="myform">
                    <input type="hidden" name="contacts.id" value="${contacts.id }" />
                    <fieldset>
                        <div class="control-group" id="namediv">
                            <label class="control-label" for="name">姓名</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="name" name="contacts.name" value="${contacts.name }">
                            </div>
                        </div>
                        <div class="control-group" id="companydiv">
                            <label class="control-label" for="company">公司</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="company" name="contacts.companyName" value="${contacts.companyName }">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="company">职位</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" name="contacts.title" value="${contacts.title }">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">电话</label>
                            <div class="controls">
                                <c:forEach items="${contacts.telSet }" var="tel">
                                	<div style="margin-bottom:5px;" class="mobileDiv">
                                    	<input type="hidden" name="mobileid" value="${tel.id }">
	                                    <input type="text" class="input-xlarge" name="mobile" value="${tel.tel }">
	                                    <select name="mobileType">
		                                    <c:choose>
		                                    	<c:when test="${tel.type eq '手机' }">
		                                    		<option value="手机" selected="selected">手机</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="手机">手机</option>
		                                    	</c:otherwise>
		                                    </c:choose>
		                                    <c:choose>
		                                    	<c:when test="${tel.type eq '单位' }">
		                                    		<option value="单位" selected="selected">单位</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="单位">单位</option>
		                                    	</c:otherwise>
		                                    </c:choose>
		                                    <c:choose>
		                                    	<c:when test="${tel.type eq '住宅' }">
		                                    		<option value="住宅" selected="selected">住宅</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="住宅">住宅</option>
		                                    	</c:otherwise>
		                                    </c:choose>
		                                    <c:choose>
		                                    	<c:when test="${tel.type eq '传真' }">
		                                    		<option value="传真" selected="selected">传真</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="传真">传真</option>
		                                    	</c:otherwise>
		                                    </c:choose>
	                                    	<c:choose>
		                                    	<c:when test="${tel.type eq '总机' }">
		                                    		<option value="总机" selected="selected">总机</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="总机">总机</option>
		                                    	</c:otherwise>
		                                    </c:choose>
	                                    	<c:choose>
		                                    	<c:when test="${tel.type eq '传呼机' }">
		                                    		<option value="传呼机" selected="selected">传呼机</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="传呼机">传呼机</option>
		                                    	</c:otherwise>
		                                    </c:choose>
	                                    </select>
	                                    <i class="icon-plus-sign" onclick="newmobile(this)"></i><i class="icon-minus-sign" onclick="delmobile(this)"></i>
	                                </div>
                                </c:forEach>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="email">邮箱</label>
                            <div class="controls">
                            	<c:forEach items="${contacts.mailSet }" var="email">
                            		<input type="hidden" name="emailid" value="${email.id }"/>
	                            	<div style="margin-bottom:5px;" class="emailDiv">
	                            		<input type="text" class="input-xlarge" name="email" value="${email.mail }">
		                                <select name="emailType">
		                                	<c:choose>
		                                    	<c:when test="${email.type eq '家用' }">
		                                    		<option value="家用" selected="selected">家用</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="家用">家用</option>
		                                    	</c:otherwise>
		                                    </c:choose>
		                                   	<c:choose>
		                                    	<c:when test="${email.type eq '单位' }">
		                                    		<option value="单位" selected="selected">单位</option>
		                                    	</c:when>
		                                    	<c:otherwise>
		                                    		<option value="单位">单位</option>
		                                    	</c:otherwise>
		                                    </c:choose>
		                                </select>
		                                <i class="icon-plus-sign" onclick="newemail(this)"></i><i class="icon-minus-sign" onclick="delemail(this)"></i>
	                            	</div>
                            	</c:forEach>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="weibo">微博</label>
                            <div class="controls">
                                <div class="input-prepend">
                                    <input type="text" class="input-xlarge" name="contacts.weibo" value="${contacts.weibo }">
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="home_page">主页</label>
                            <div class="controls">
                                <div class="input-prepend">
                                    <span class="add-on">http://</span><input type="text" class="input-large" id="home_page" name="contacts.website" value="${contacts.website }">
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="im">IM</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" name="contacts.im" value="${contacts.im }">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="address">地址</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" name="contacts.address" value="${contacts.address }">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="Introduction">简介</label>
                            <div class="controls">
                                <textarea name="contacts.content" id="Introduction" class="input-xlarge" rows="6">${contacts.content }</textarea>
                            </div>
                        </div>
                        <div class="control-group">
							<label class="control-label">谁可以看到</label>
							<div class="controls">
								<label class="radio">
									<input type="radio" name="view" value="all" />所有人<br/>
								</label>
								<label class="radio">
									<input type="radio" name="view" value="me" />只有我<br/>
								</label>
								<label class="radio">
									<input type="radio" name="view" value="group" data-toggle="collapse" data-target="#group" data-parent="#detail" />选择一个组<br/>
								</label>
								<div id="group" class="collapse">
                                    <select name="case" name="group" style="width:150px">
                                        <option value="">--请选择一个分组--</option>
                                        <c:forEach items="${userGroupList }" var="group">
                                        	<option value="${group.id }">${group.groupName }</option>
                                        </c:forEach>
                                    </select>
                                </div>
                                <label class="radio">
                                	<input type="radio" name="view" value="people" data-toggle="collapse" data-target="#people" data-parent="#detail" />选择一些人<br/>
                                </label>
                                <div id="people" class="collapse">
                                	<c:forEach items="${userList }" var="user">
                                		<input type="checkbox" name="people" value="${user.id }" />${user.username }
                                    </c:forEach>
                                </div>
							</div>
						</div>
                        <div class="form-actions">
                            <button class="btn btn-primary" type="submit" id="btn">保存</button>
                            <a href="${basePath }/contacts/list" class="btn">返回</a>
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
        
        <div class="span3 well" style="padding-top:0px">
            <div class="box">
                <div class="head">今日任务</div>
                <ul style="list-style-type:none">
                    <li>
                        <input type="checkbox" /> <a href="task?id=${task.goalId }" class="link-black">我的任务</a>
                    </li>
                    <li>
                        <input type="checkbox" /> <a href="task?id=${task.goalId }" class="link-black">我的任务</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function newmobile(txt) {
        	var input = $(txt).siblings($(".input-xlarge"));
        	if (input.val().trim() == "") {
        		return;
        	}
            var parentDiv = $(txt).parent().parent();
            var div = $("<div>").attr("style","margin-bottom:5px;").attr("class","mobileDiv");
            $("<input>").attr("type","text").attr("class","input-xlarge").attr("name","mobile").appendTo($(div));
            $(div).append(" ");
            var select = $("<select>").attr("name","mobileType");
			$(select).append("<option value='手机'>手机</option>");
			$(select).append("<option value='单位'>单位</option>");
			$(select).append("<option value='住宅'>住宅</option>");
			$(select).append("<option value='传真'>传真</option>");
			$(select).append("<option value='总机'>总机</option>");
			$(select).append("<option value='传呼机'>传呼机</option>");
			$(select).appendTo($(div));
			$(div).append(" ");
            $("<i>").addClass("icon-plus-sign").attr("onclick","newmobile(this)").appendTo($(div));
            $("<i>").addClass("icon-minus-sign").attr("onclick","delmobile(this)").appendTo($(div));
            $(div).appendTo($(parentDiv));
        }
        function delmobile(txt) {
            var length = $(".mobileDiv").length;
            if (length != 1) {
                var parentDiv = $(txt).parent();
                $(parentDiv).remove();
            }
        }
        function newemail(txt) {
        	var input = $(txt).siblings($(".input-xlarge"));
        	if (input.val().trim() == "") {
        		return;
        	}
            var parentDiv = $(txt).parent().parent();
            var div = $("<div>").attr("style","margin-bottom:5px;").attr("class","emailDiv");
            $("<input>").attr("type","text").attr("class","input-xlarge").attr("name","email").appendTo($(div));
            $(div).append(" ");
            var select = $("<select>").attr("name","emailType");
			$(select).append("<option value='家用'>家用</option>");
			$(select).append("<option value='单位'>单位</option>");
			$(select).appendTo($(div));
			$(div).append(" ");
            $("<i>").addClass("icon-plus-sign").attr("onclick","newemail(this)").appendTo($(div));
            $("<i>").addClass("icon-minus-sign").attr("onclick","delemail(this)").appendTo($(div));
            $(div).appendTo($(parentDiv));
        }
        function delemail(txt) {
            var length = $(".emailDiv").length;
            if (length != 1) {
                var parentDiv = $(txt).parent();
                $(parentDiv).remove();
            }
        }
    </script>
</body>
</html>